package com.github.yoojia.mqtt.boot.utils;

import com.parkingwang.lang.ThrowSupplier;
import com.parkingwang.lang.Try;

/**
 * @author Yoojia Chen (yoojiachen@gmail.com)
 * @since 1.0
 */
public class Classes {

    @SuppressWarnings("unchecked")
    public static <T> T newInstance(final String className){
        return Try.die(new ThrowSupplier<T>() {
            @Override
            public T call() throws Throwable {
                return (T) Try.die(new ThrowSupplier<Class>() {
                    @Override
                    public Class call() throws Throwable {
                        return Classes.class.getClassLoader().loadClass(className);
                    }
                }).newInstance();
            }
        });
    }
}
